<template>
  <el-carousel :interval="4000" type="card" height="200px">
    <el-carousel-item v-for="(item, index) in bannerList" :key="index">
      <!-- <h3 class="medium">{{ item }}</h3> -->
      <a :href="item.url" target="_blank">
        <img :src="item.imageUrl">
      </a>
    </el-carousel-item>
  </el-carousel>
</template>

<script>
import { getBanner } from '@/api/banner.js'
export default {
  data () {
    return {
      bannerList: []
    }
  },
  created () {
    this.showBanner()
  },
  methods: {
    async showBanner () {
      const res = await getBanner()
      if (res.status !== 200) return this.$message.error('获取轮播图失败')
      // 保存轮播图数据
      this.bannerList = res.data.banners
      // console.log(res)
    }
  }
}
</script>

<style lang="less" scoped>
img {
  height: 100%;
  max-width: 100%;
}
</style>
